Public Class cls_Table_Update
    Inherits cls_Database_Base
#Region "Count table"
    Public Function FuncG_CountTable(ByVal iByte_Status As Byte) As Integer
        Dim mvStr_Sql As String = ""
        Try
            If FuncM_OpenConnection() Then
                mvStr_Sql = "SELECT COUNT(TBL_TABLE.ID) FROM [TBL_TABLE] INNER JOIN"
                mvStr_Sql += "  TBL_AREA ON TBL_TABLE.LOC_ID = TBL_AREA.LOC_ID AND TBL_TABLE.AREA_ID = TBL_AREA.ID"
                mvStr_Sql += "  WHERE TBL_TABLE.LOC_ID = @iNVChr_LOCID AND TBL_TABLE.STATUS = @iTInt_STATUS AND TBL_AREA.STATUS <> 0"
                SubM_AddParameter("@iNVChr_LOCID", gvStr_LocID)
                SubM_AddParameter("@iTInt_STATUS", iByte_Status)
                Return FuncM_ExecuteScalar(mvStr_Sql)
            End If
        Catch ex As Exception
            Return 0
            Throw ex
        Finally
            FuncM_CloseConnection()
        End Try
        Return 0
    End Function
    Public Function FuncG_CountTable(ByVal iStr_AreaID As String, ByVal iByte_Status As Byte) As Integer
        Dim mvStr_Sql As String = ""
        Try
            If FuncM_OpenConnection() Then
                mvStr_Sql = "SELECT COUNT(TBL_TABLE.ID) FROM [TBL_TABLE] INNER JOIN"
                mvStr_Sql += "  TBL_AREA ON TBL_TABLE.LOC_ID = TBL_AREA.LOC_ID AND TBL_TABLE.AREA_ID = TBL_AREA.ID"
                mvStr_Sql += "  WHERE TBL_TABLE.LOC_ID = @iNVChr_LOCID AND TBL_TABLE.STATUS = @iTInt_STATUS AND TBL_TABLE.AREA_ID = @iNVChr_AREAID AND TBL_AREA.STATUS <> 0"
                SubM_AddParameter("@iNVChr_LOCID", gvStr_LocID)
                SubM_AddParameter("@iNVChr_AREAID", iStr_AreaID)
                SubM_AddParameter("@iTInt_STATUS", iByte_Status)
                Return FuncM_ExecuteScalar(mvStr_Sql)
            End If
        Catch ex As Exception
            Return 0
            Throw ex
        Finally
            FuncM_CloseConnection()
        End Try
        Return 0
    End Function
#End Region
#Region "Get Data"
    Public Function FuncG_GetData(ByVal iStr_AreaID As String) As DataTable
        Dim mvDataTale As New DataTable
        Dim mvStr_Sql As String = ""
        Try
            If FuncM_OpenConnection() Then
                mvStr_Sql = "SELECT * FROM [TBL_TABLE] WHERE LOC_ID = @iNVChr_LOCID AND AREA_ID = @iNVChr_AREAID ORDER BY [ID]"
                SubM_AddParameter("@iNVChr_LOCID", gvStr_LocID)
                SubM_AddParameter("@iNVChr_AREAID", iStr_AreaID)
                mvDataTale = FuncM_GetDataTable(mvStr_Sql)
            End If
        Catch ex As Exception
            Throw ex
        Finally
            FuncM_CloseConnection()
        End Try
        Return mvDataTale
    End Function
    Public Function FuncG_GetDataInfo(ByVal iStr_ID As String) As DataTable
        Dim mvDataTale As New DataTable
        Dim mvStr_Sql As String = ""
        Try
            If FuncM_OpenConnection() Then
                mvStr_Sql = "SELECT * FROM [TBL_TABLE] WHERE LOC_ID = @iNVChr_LOCID AND [ID] = @iNVChr_ID ORDER BY [ID]"
                SubM_AddParameter("@iNVChr_LOCID", gvStr_LocID)
                SubM_AddParameter("@iNVChr_ID", iStr_ID)
                mvDataTale = FuncM_GetDataTable(mvStr_Sql)
            End If
        Catch ex As Exception
            Throw ex
        Finally
            FuncM_CloseConnection()
        End Try
        Return mvDataTale
    End Function
#End Region
#Region "Insert - Update"
    Public Function FuncG_InsertUpdateDelete(ByVal iCls_Table As cls_Table) As Boolean
        Try
            If FuncM_OpenConnection() Then
                SubM_AddParameter("@iNVChr_LOCID", gvStr_LocID)
                SubM_AddParameter("@iInt_ID", iCls_Table.ID)
                SubM_AddParameter("@iNVChr_NAME", iCls_Table.Name)
                SubM_AddParameter("@iTInt_STATUS", iCls_Table.Status)
                If FuncM_ExecuteStore("usp_Table") Then
                    Return True
                Else
                    Return False
                End If
            End If
        Catch ex As Exception
            Throw ex
            Return False
        Finally
            FuncM_CloseConnection()
        End Try
    End Function
#End Region
End Class
